<?php
	include('modele_Connexion.php');
	
	if (isset($_POST['do'])){
		if($_POST['do'] == "modifierPage"){
			
			$req = $bdd->prepare('UPDATE pages SET contenuPage = :contenu, libellePage = :titre WHERE numPage = :numPage ');
			$req->execute(array(
				'contenu' => $_POST['contenu'],
				'titre' => $_POST['titre'],
				'numPage' => $_POST['numPage']
				));
			
			header('Location:index.php?page=Admin');
		}
		else if($_POST['do'] == "creerEvent"){
			
			$req = $bdd->prepare('INSERT INTO evenements(calEvt, dateDebEvt, dateFinEvt, lieuEvt, libelleEvt, descriptionEvt) VALUES(:idCal, :dateDebut, :dateFin, :lieu, :libelle, :description)');
			$req->execute(array(
				'idCal' => 1,
				'dateDebut' => $_POST['yearDebut']."-".$_POST['monthDebut']."-".$_POST['dayDebut']." ".$_POST['hourDebut'].":".$_POST['minDebut'].":00",
				'dateFin' => $_POST['yearFin']."-".$_POST['monthFin']."-".$_POST['dayFin']." ".$_POST['hourFin'].":".$_POST['minFin'].":00",
				'lieu' => $_POST['lieu'],
				'libelle' => $_POST['EventName'],
				'description' => $_POST['EventDescription']
				));
				
			header('Location:index.php?page=Admin');
			
		}
		else if($_POST['do'] == "modifierSsPage"){
		
			$req = $bdd->prepare('UPDATE souspages SET contenuSsPage = :contenu WHERE idSsPage = :numPage ');
			$req->execute(array(
				'contenu' => $_POST['contenu'],
				'numPage' => $_POST['idSsPage']
				));
			//echo '<script language="Javascript"> document.location.replace("index.php?page=Accueil"); 	</script>';
			header('Location:index.php?page=Admin');
		}
		else if($_POST['do'] == "modifierEvent"){ 
			$dd = $_POST['yearDebut']."-".$_POST['monthDebut']."-".$_POST['dayDebut']." ".$_POST['hourDebut'].":".$_POST['minDebut'].":00";
			$df = $_POST['yearFin']."-".$_POST['monthFin']."-".$_POST['dayFin']." ".$_POST['hourFin'].":".$_POST['minFin'].":00";
			
			$req = $bdd->prepare('UPDATE evenements SET dateDebEvt = :dateDebut, dateFinEvt = :dateFin, lieuEvt = :lieu, libelleEvt = :libelle, descriptionEvt = :description WHERE idEvt = :idevt');
			$req->execute(array(
				'idevt' => $_POST['idEvt'],
				'dateDebut' => $dd,
				'dateFin' => $df,
				'lieu' => $_POST['lieu'],
				'libelle' => $_POST['EventName'],
				'description' => $_POST['EventDescription']				
				));
			header('Location:index.php?page=Admin');
		}
		else if($_POST['do'] == "eventDelete"){ 
			
			$req = $bdd->prepare('DELETE FROM evenements WHERE idEvt = :idevt');
			$req->execute(array(
				'idevt' => $_POST['idEvt']
				));
			
			header('Location:index.php?page=Admin');
		}
		else if($_POST['do'] == "deletePj"){ 
			
			$req = $bdd->prepare('DELETE FROM pieces_jointes WHERE idPj = :idPj');
			$req->execute(array(
				'idPj' => $_POST['idPj']
				));
			
			header('Location:index.php?page=Admin');
		}
		
		
	}
	else{
		header('Location:index.php?page=Admin');
	}
?>